<!--
~ Copyright 2018-present Open Networking Foundation
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~     http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<div id="ov-flow" xmlns="http://www.w3.org/1999/html">
    <onos-loading [theme]="'light'" [running]="loadingIconShown"></onos-loading>
    <div class="tabular-header">
        <h2>
            {{lionFn('title_flows')}} {{id}} ({{ tableData.length }} {{ lionFn('total') }})
        </h2>
        <div class="ctrl-btns">
            <div class="refresh" (click)="toggleRefresh()">
                <!-- See icon.theme.css for the defintions of the classes active and refresh-->
                <onos-icon classes="{{ autoRefresh?'active refresh':'refresh' }}" iconId="refresh" iconSize="42" toolTip="{{ autoRefreshTip }}"></onos-icon>
            </div>
            <div class="separator"></div>
            <span *ngIf="brief" (click)="briefToggle()">
                <div>
                    <onos-icon classes="{{ id ? 'active-rect' :undefined}}" iconId="plus" iconSize="42" toolTip="{{detailTip}}"></onos-icon>
                </div>
            </span>

            <span *ngIf="!brief" (click)="briefToggle()">
                <div>
                    <onos-icon classes="{{ id ? 'active-rect' :undefined}}" iconId="minus" iconSize="42" toolTip="{{briefTip}}"></onos-icon>
                </div>
            </span>
            <div class="separator"></div>
            <div routerLink="/device" [queryParams]="{ devId: id }" routerLinkActive="active">
                <onos-icon classes="{{ id ? 'active-rect':undefined }}" iconId="deviceTable" iconSize="42" toolTip="{{deviceTip}}"></onos-icon>
            </div>

            <div>
                <onos-icon classes="{{ id ? 'current-view' :undefined}}" iconId="flowTable" iconSize="42"></onos-icon>
            </div>

            <div routerLink="/port" [queryParams]="{ devId: id }" routerLinkActive="active">
                <onos-icon classes="{{ id ? 'active-rect' :undefined}}" iconId="portTable" iconSize="42" toolTip="{{ portTip }}"></onos-icon>
            </div>

            <div routerLink="/group" [queryParams]="{ devId: id }" routerLinkActive="active">
                <onos-icon classes="{{ id ? 'active-rect' :undefined}}" iconId="groupTable" iconSize="42" toolTip="{{ groupTip }}"></onos-icon>
            </div>

            <div routerLink="/meter" [queryParams]="{ devId: id }" routerLinkActive="active">
                <onos-icon classes="{{ id ? 'active-rect' :undefined}}" iconId="meterTable" iconSize="42" toolTip="{{ meterTip }}"></onos-icon>
            </div>

            <div routerLink="/pipeconf" [queryParams]="{ devId: id }" routerLinkActive="active">
                <onos-icon classes="{{ id ? 'active-rect' :undefined}}" iconId="pipeconfTable" iconSize="42" toolTip="{{ pipeconfTip }}"></onos-icon>
            </div>
        </div>
        <div class="search">
            <input id="searchinput" [(ngModel)]="tableDataFilter.queryStr" type="search" #search placeholder="Search" />
            <select [(ngModel)]="tableDataFilter.queryBy">
                <option value="" disabled>Search By</option>
                <option value="$">All Fields</option>
                <option value="priority">{{lionFn('priority')}}</option>
                <option value="tableName">{{lionFn('tableName')}}</option>
                <option value="selector">{{lionFn('selector')}}</option>
                <option value="treatment">{{lionFn('treatment')}}</option>
                <option value="appName">{{lionFn('appName')}}</option>
            </select>
        </div>
    </div>

    <div class="summary-list" onosTableResize>
        <div class="table-header">
            <table>
                <tr>
                    <td class="col8pct" colId="state" (click)="onSort('state')">{{lionFn('state')}}
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('state')"></onos-icon>
                    </td>
                    <td class="col8pct" colId="packets" (click)="onSort('packets')">{{lionFn('packets')}}
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('packets')"></onos-icon>
                    </td>
                    <td class="col10pct" colId="duration" (click)="onSort('duration')">{{lionFn('duration')}}
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('duration')"></onos-icon>
                    </td>
                    <td class="col8pct" colId="priority" (click)="onSort('priority')">{{lionFn('priority')}}
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('priority')"></onos-icon>
                    </td>
                    <td colId="tableName" (click)="onSort('tableName')">{{lionFn('tableName')}}
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('tableName')"></onos-icon>
                    </td>
                    <td colId="selector" (click)="onSort('selector')">{{lionFn('selector')}}
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('selector')"></onos-icon>
                    </td>
                    <td colId="treatment" (click)="onSort('treatment')">{{lionFn('treatment')}}
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('treatment')"></onos-icon>
                    </td>
                    <td class="col8pct" colId="appName" (click)="onSort('appName')">{{lionFn('appName')}}
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('appName')"></onos-icon>
                    </td>
                </tr>
            </table>
        </div>

        <div class="table-body">
            <table>
                <tr class="table-body" *ngIf="tableData.length === 0" class="no-data">
                    <td colspan="9">{{annots.noRowsMsg}}</td>
                </tr>
                <ng-template ngFor let-flow [ngForOf]="tableData | filter : tableDataFilter">
                    <tr (click)="selectCallback($event, flow)" [ngClass]="{selected: flow.id === selId, 'data-change': isChanged(flow.id)}">
                        <td class="col8pct">{{flow.state}}</td>
                        <td class="col8pct">{{flow.packets}}</td>
                        <td class="col10pct">{{flow.duration}}</td>
                        <td class="col8pct">{{flow.priority}}</td>
                        <td>{{flow.tableName}}</td>
                        <td>{{flow.selector_c}}</td>
                        <td>{{flow.treatment_c}}</td>
                        <td class="col10pct">{{flow.appName}}</td>
                    </tr>
                    <tr (click)="selectCallback($event, flow)" [ngClass]="{selected: flow.id === selId, 'data-change': isChanged(flow.id)}" [hidden]="brief">
                        <td class="selector" colspan="8">{{flow.selector}} </td>
                    </tr>
                    <tr (click)="selectCallback($event, flow)" [ngClass]="{selected: flow.id === selId, 'data-change': isChanged(flow.id)}" [hidden]="brief">
                        <td class="treatment" colspan="8">{{flow.treatment}}</td>
                    </tr>
                </ng-template>
            </table>
        </div>
    </div>
    <onos-flowdetails class="floatpanels" flowId="{{ selId }}" appId="{{ selRowAppId }}" (closeEvent)="deselectRow($event)"></onos-flowdetails>
</div>
